import 'package:flutter/material.dart';

class SwitchHomePage extends StatefulWidget {
  @override
  _SwitchHomePageState createState() => _SwitchHomePageState();
}

class _SwitchHomePageState extends State<SwitchHomePage> {
  bool select = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("switch配置"),
        ),
        // 线性布局
        body: Column(
          children: <Widget>[
            // 可用container 和 sizedbox容器对switch进行宽度的控制
            SizedBox(
              width: 100,
              child: Switch(
                // 开关开启时的圆点颜色 默认 ThemeData accentColor
                activeColor: Colors.blue,
                // 开关开启时的底座颜色
                activeTrackColor: Colors.yellow,
                // 开关开启时圆点的背景照片
                activeThumbImage: AssetImage("images/3.0/selected.jpg"),
                // 开关关闭时的圆点颜色
                inactiveThumbColor: Colors.deepPurple,
                // 开关关闭状态时底座的颜色
                inactiveTrackColor: Colors.grey,
                // 开关关闭时圆点的背景照片
                inactiveThumbImage: AssetImage("images/3.0/unselected.jpg"),
                // 开关状态
                value: select,
                onChanged: (value) {
                  setState(() {
                    select = value;
                  });
                },
              ),
            ),
            SwitchListTile(
                value: select,
                title: Text("这是标题"),
                subtitle: Text("这是二级标题"),
                secondary: Image.asset(
                  'images/3.0/logo.jpg',
                  width: 55,
                ),
                onChanged: (value) {
                  setState(() {
                    select = value;
                  });
                }),
          ],
        ));
  }
}
